<template>
  <div class="_wz_cent_main _wz_materialLibrary">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="课件名称">
          <i-input v-model="formDataSearch.materialName" placeholder="课件名称" clearable />
        </FormItem>
        <FormItem label="课件方向">
          <i-select v-model="formDataSearch.materialDirection" filterable placeholder="课件方向" clearable>
            <Option v-for="item in optionsData" :value="item.code" :key="item.code">{{ item.value }}</Option>
          </i-select>
        </FormItem>
        <FormItem label="课件类型" v-if="searchType">
          <i-select v-model="formDataSearch.materialType" filterable placeholder="课件类型" clearable>
            <Option value="1">视频课件</Option>
            <Option value="2">文档课件</Option>
          </i-select>
        </FormItem>
        <FormItem label="审核状态" v-if="searchType">
          <i-select v-model="formDataSearch.materialAudit" filterable placeholder="审核状态" clearable>
            <Option value="0">审核中</Option>
            <Option value="1">审核通过</Option>
            <Option value="-1">未通过</Option>
          </i-select>
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">
        列表
        <span style="color: #ed4014;margin: 0 0 0 10px;font-weight: 600;font-size: 12px;">审核素材时间为：9:00-18:00；如使用授权课件，请联系商务人员。</span>
      </p>


      <p slot="extra">
        <Button type="primary" @click="addTableData">添加</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>
    <Drawer :title="formTitle" v-model="formOperation" width="720" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <MaterialAdd v-if="formOperation" @closeFun="closeFun" :selectData="selectData"></MaterialAdd>
    </Drawer>

    <Drawer v-model="modal" title="课件查看" width="700" :draggable="true">
      <materialVideo v-if="modal && materialType==1" :materialData="materialData"></materialVideo>
      <materialIframe v-else-if="modal && materialType==5" :materialData="materialData"></materialIframe>
    </Drawer>


    <Modal v-model="qureyOverruleReasonType" title="驳回原由" :footer-hide="true">
      <Timeline>
        <TimelineItem v-for="item in qureyOverruleReason" :key="item.id">
          <p class="time">{{item.createTime}}</p>
          <p class="content">{{item.materialAuditOverruleReason}}</p>
        </TimelineItem>
      </Timeline>
    </Modal>
  </div>
</template>
<script>
  import MaterialAdd from './MaterialAdd.vue'

  import materialIframe from '../public/materialIframe.vue'
  import materialVideo from '../public/materialVideo.vue'
  import wzTbale from "../../../components/table/table";

  export default {
    components: {
      materialIframe,//文档
      materialVideo,//视频
      MaterialAdd,//添加
      wzTbale,//列表
    },
    data() {
      return {
        subDeptList: [],//运输企业
        searchType:false,//搜索条件
        optionsData: [],//下拉加载
        //查看素材
        modal: false,//弹出层状态
        materialType: 0,//6 试题   5 html   1 视频
        materialData: {},//查看课件全部数据
        formDataSearch: {
          materialOpen: 0
        },//搜索表单数据

        selectData: {},//选择数据
        formTitle: "",//表单名称

        qureyOverruleReason: [],//驳回原因list
        qureyOverruleReasonType: false,//驳回弹出


        //添加修改
        formOperation: false,//表单左侧移出
        formOperationStyles: {//表单左侧移出css
          height: 'calc(100% - 55px)',
          overflow: 'auto',
          paddingBottom: '53px',
          position: 'static'
        },

        tableData: {
          url: this.apiUrl.webApi + "/educate/materialTrain/materialTrainPageList",//请求地址
          method: 'post',//请求方式
          where: {materialOpen: 0},//搜索条件
          height: 'auto',//表格高度 auto
          page: true,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 70, align: 'center', title: '序号'},
            {title: '培训课件', minWidth: 220, key: 'materialTrainName'},
            {title: '培训类型', minWidth: 110, key: 'materialTrainTransportTypeName'},
            {title: '课件方向', minWidth: 110, key: 'materialTrainDirectionName'},
            {
              title: '学习时长', minWidth: 100,
              render: (h, params) => {
                return h('span', params.row.materialTrainDuration + '分钟');
              }
            },
            {
              title: '文件类型', minWidth: 100,
              render: (h, params) => {
                return h('div', [
                  h('i', {
                    class: [(params.row.materialTrainType == 1) ? "fa fa-file-movie-o" : "fa fa-file-word-o"],
                    style: {
                      color: (params.row.materialTrainType == 1) ? "#2d8cf0" : "#009688",
                      "font-size": "12px",
                      "margin": "0px 5px 0px 0px",
                    },
                  }, ''),
                  h('span', params.row.materialTrainType == 1 ? '视频' : '文本')
                ])
              }
            },
            {title: '上传时间', minWidth: 160, key: 'createTime'},
            {
              title: '审核状态', minWidth: 140, render: (h, params) => {
                //  0：审核中，1：通过，-1：未通过
                if (params.row.materialTrainAudit == 1) {
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '审核通过')
                } else if (params.row.materialTrainAudit == 0) {
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '审核中')
                } else {
                  return h('Tag', {props: {type: 'dot',color: 'error'}}, '审核驳回')
                }
              }
            },
            {
              title: '处理状态', minWidth: 140, render: (h, params) => {
                //  0：审核中，1：通过，-1：未通过
                var test = '';
                if (params.row.materialTrainProcess == 1) {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'success'
                    }
                  }, '处理通过')
                } else if (params.row.materialTrainProcess == 0) {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'warning'
                    }
                  }, '处理中')
                } else {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'error'
                    }
                  }, '处理失败')
                }
                return test;
              }
            },
            {title: '运输企业', minWidth: 260, key: 'deptName'},
            {
              title: '操作', fixed: 'right', width: 130,
              render: (h, params) => {
                let operationButtons = [];
                if (params.row.materialTrainProcess == 1) {//处理完成
                  operationButtons.push(h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.handleViewFun(params.row)
                      }
                    }
                  }, '查看'))
                }else{
                  //修改
                  operationButtons.push(h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.formTitle = "修改";
                        this.selectData = JSON.parse(JSON.stringify(params.row));
                        this.formOperation = true;
                      }
                    }
                  }, '修改'))
                }

                operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                //删除
                operationButtons.push(h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.removeTableFun(params.row)
                    }
                  }
                }, '删除'))
                return operationButtons;
              }
            }
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
            count: ['count'],//数据总量
          },
        },

      }
    },
    beforeCreate() {//beforeCreate创建前状态
    },
    created() {//created创建完毕状态
    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程
    },
    mounted() {//mounted 挂载结束状态
      let that = this;

      //运输企业
      that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
        if (!!res) {
          that.subDeptList = res.data.data;
        }
      }).catch(err => {
        console.log("失败", err)
      })


      //加载方向
      that.axios.post(that.apiUrl.systemDictSystemDictList, {type: 'training_direction'}).then(res => {
        if (!!res) {
          that.optionsData = res.data.data
        }
      }).catch(err => {
        console.log('失败', err)
      })
    },
    methods: {//执行的方法
      //删除
      removeTableFun(data) {
        let that = this;
        that.$Modal.confirm({
          title: '删除提醒',
          content: '确定要删除选中的记录？',
          onOk: () => {
            that.tableLoading = true;//加载
            that.axios.post(that.apiUrl.webApi + "/educate/materialTrain/materialTrainDelete", {materialUuid: data.uuid}).then(res => {
              that.tableLoading = false;//加载
              if (!!res) {
                that.$Message.success('删除成功');
                that.$refs.wzTbale.tableLoadData();
              }
            }).catch(err => {
              console.log('失败', err);
            })
          },
          onCancel: () => {
            //点击取消
          }
        });

      },
      //table添加
      addTableData() {
        let that = this;
        that.formTitle = "添加";
        that.selectData = {};
        that.formOperation = true;
      },
      //搜索
      searchSubmit() {
        this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
        this.$refs.wzTbale.tableLoadData(true);
      },
      //添加修改触发后关闭刷新
      closeFun(data) {
        if (data) {//添加修改 刷新表单
          this.$refs.wzTbale.tableLoadData();
        }
        this.formOperation = false;
      },

      //查看素材
      handleViewFun(src) {
        let that = this;
        that.materialType = 0;
        that.materialData = {};
        if (src.materialTrainType == 2) {//文档路径  和 mp3 路径
          that.materialData.htmlUrl = src.materialTrainHtmlUrl;//文件路径
          that.materialData.mp3Url = src.materialTrainMp3Url;//mp3路径
          that.materialType = 5;//5 html   1 视频
        } else {//视频路径
          that.materialData.videoSdUrl = src.materialTrainVideoSdUrl;//标清：SD
          if (!!src.materialTrainVideoHdUrl) {//高清：HD
            that.materialData.videoHdUrl = src.materialTrainVideoHdUrl;
          }
          if (!!src.materialTrainVideoFdUrl) {//超清：FD
            that.materialData.videoFdUrl = src.materialTrainVideoFdUrl;
          }
          that.materialType = 1;//5 html   1 视频
        }
        that.modal = true;
      },
    },
    watch: {//监听

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>
<style lang="less">
  ._wz_materialLibrary {
    height: 100%;
    display: flex;
    flex-direction: column;





  }
</style>
